package 实验八网络编程2;
import java.io.*;  
import java.net.ServerSocket;  
import java.net.Socket;  
  
public class 八杠二服务端 {  
    public static void main(String[] args) {  
        try (ServerSocket serverSocket = new ServerSocket(9999)) {  
            System.out.println("服务器已启动，等待客户端连接...");  
  
            while (true) {  
                Socket socket = serverSocket.accept();  
                new Thread(new ServerThread(socket)).start();  
            }  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }  
}  
  
class ServerThread implements Runnable {  
    private final Socket socket;  
  
    public ServerThread(Socket socket) {  
        this.socket = socket;  
    }  
  
    @Override  
    public void run() {  
        try (BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));  
             PrintWriter out = new PrintWriter(socket.getOutputStream(), true)) {  
            String question;  
            while ((question = in.readLine()) != null) {  
                switch (question) {  
                    case "你是谁？":
                    	{
                        out.println("我是 刘权林");  
                        break;  }
                    case "你的爱好是什么？":
                    	{
                    	
                    	out.println("编java程序");  
                    	 break; 
                    	}
                    default:  
                        out.println("你说啥呢!");  
                        break;  
                }  
            }  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }  
}